package cn.edu.scau.cmi.wujiaxian.exercise10;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;


public class Example10_11 {
	
	//数据流，可以读写对应类型的数据，可以用在数据库的操作上
	public static void main(String[] args) {
		File file = new File("apple.txt");
		try {
			FileOutputStream fos = new FileOutputStream(file);
			DataOutputStream dos = new DataOutputStream(fos);
			dos.writeInt(100);
			dos.writeLong(123456);
			dos.writeBoolean(true);
			dos.writeUTF(new String("How are you doing"));
			dos.writeLong(123456);
			dos.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		FileInputStream fis;
		try {
			fis = new FileInputStream(file);
			DataInputStream dis = new DataInputStream(fis);
			System.out.println(dis.readInt());
			System.out.println(dis.readLong());
			System.out.println(dis.readBoolean());
			System.out.println(dis.readUTF());
			System.out.println(dis.readLong());
			dis.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}
	
}
